Percona XtraDB Cluster (docker 实践)

PXC(Percona XtraDB Cluster),Percona Xtradb Cluster的实现是在原mysql代码上通过Galera包将不同的mysql实例连接起来,实现了multi-master的集群架构

Percona XtraDBCluster提供的特性有:

  1. 同步复制,事务要么在所有节点提交或不提交。
  2. 多主复制,可以在任意节点进行写操作。
  3. 在从服务器上并行应用事件,真正意义上的并行复制。
  4. 节点自动配置。
  5. 数据一致性,不再是异步复制。

安装 pxc

docker pull percona/percona-xtradb-cluster 一般使用 5.7 版本 docker pull percona/percona-xtradb-cluster:5.7

percona-xtradb-cluster 名字太长,命令行中不方便输入,使用 tag 命令修改名称

docker tag percona/percona-xtradb-cluster:5.7 pxc

pxc 应当3个节点以上部署,当只有两个节点,挂掉一个只剩下一个的时候,会出现【WSREP has not yet prepared node for application use】的错误 需要设置 SET GLOBAL wsrep_provider_options='pc.bootstrap=YES';

To override this protection, edit the safe_to_bootstrap line in the grastate.dat file of the node you intend to use as the first node.

pxc单服务器配置

        # 创建网络
        docker network create pxc-network
        # node1
        docker run -d \
            -e MYSQL_ROOT_PASSWORD=root \
            -e CLUSTER_NAME=cluster \
            --name=node1 \
            --user=mysql \
            --net=pxc-network \
            percona/percona-xtradb-cluster:5.7  
        # node2
        docker run -d \
            -e MYSQL_ROOT_PASSWORD=root \
            -e CLUSTER_NAME=cluster \
            -e CLUSTER_JOIN=node1 \
            --name=node2 \
            --user=mysql \
            --net=pxc-network \
            percona/percona-xtradb-cluster:5.7
        # node3
        docker run -d \
            -e MYSQL_ROOT_PASSWORD=root \
            -e CLUSTER_NAME=cluster \
            -e CLUSTER_JOIN=node1 \
            --user=mysql \
            --name=node3 \
            --net=pxc-network \
            percona/percona-xtradb-cluster:5.7     

pxc多服务器配置

关闭防火墙或者允许3306, 4444, 4567和4568四个端口的连接 关闭SElinux 防止挂载数据目录的用户权限问题,mysql_path不应该先创建起来



            # node1 192.168.2.10
            docker run -d \
                --net=host \
                -p 3306:3306 \
                -v mysql_path:/var/lib/mysql/ \
                -e CLUSTER_NAME=cluster \
                -e MYSQL_ROOT_PASSWORD=123123  \
                -e MYSQL_PROXY_PASSWORD=123123  \
                --name=node1 \
                --privileged  \
                percona/percona-xtradb-cluster:5.7

           # node2 192.168.2.11
            docker run -d \
                --net=host \
                -p 3306:3306 \
                -v mysql_path:/var/lib/mysql/ \
                -e CLUSTER_NAME=cluster \
                -e MYSQL_ROOT_PASSWORD=123123  \
                -e MYSQL_PROXY_PASSWORD=123123  \
                -e CLUSTER_JOIN=192.168.2.10 \
                --name=node2 \
                --privileged  \
                percona/percona-xtradb-cluster:5.7
# mysql 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×